import json

import pytest

from API.course import CourseAPI
from API.login import LoginAPI

class TestAddCourse:
    uuid=None
    token=None
    def setup_method(self):
        # 实例化
        self.login_api=LoginAPI()
        self.course_api=CourseAPI()
        res_v=self.login_api.get_verify_code()
        TestAddCourse.uuid=res_v.json()["uuid"]
        test_data = {

            "username": "admin",
            "password":"HM_2023_test",
            "code": "2",
            "uuid": TestAddCourse.uuid
        }
        res_login_success = self.login_api.login(test_data=test_data)
        print(res_login_success.json())
        TestAddCourse.token=res_login_success.json()["token"]
    def teardown(self):
        pass

    def test01_modify_course(self):
        test_data={"id":23056458704374123,
                    "name":"接口测试001",
                    "subject":"6",
                    "price":998,
                    "applicablePerson":"2",
                    "info":"课程介绍001"}
        res_add_course = self.course_api.modify_course(test_data=test_data, token=TestAddCourse.token)
        # print(res_add_course.json())
        assert res_add_course.status_code==200
        assert "成功" in res_add_course.text
        assert 200==res_add_course.json()["code"]
        # 2未登录
    def test02_modify_course(self):
        test_data = {"id": 23056458704374123,
                     "name": "接口测试001",
                     "subject": "6",
                     "price": 998,
                     "applicablePerson": "2",
                     "info": "课程介绍001"}
        res_add_course = self.course_api.modify_course(test_data=test_data, token="")

        assert res_add_course.status_code==200
        assert "失败" in res_add_course.text
        assert 401==res_add_course.json()["code"]

